package HLCode.ASM.value;

import HLCode.HLCustomFunction;
import HLCode.HLCustomFunction_H;
import HLCode.HLObject;

public class ASM_OwnerObject implements HLCustomFunction_H {
    public byte type;

    byte[] links;

    public int Load(byte[] data, int pos) {
        type = data[pos++];
        switch (type) {
        case OWNER_OBJECT_TYPE_IMMEDIATE_NULL: {
            break;
        }
        default: {
            int levelCount = data[pos++];
            links = new byte[levelCount];
            System.arraycopy(data, pos, links, 0, levelCount);
            pos += levelCount;
        }
        }
        return pos;
    }

    public HLObject GetValue(HLCustomFunction ownerFunction) {
        switch (type) {
        case OWNER_OBJECT_TYPE_IMMEDIATE_NULL: {
            return null;
        }
        default: {
            HLObject valueOwnerObject = ownerFunction.ownerObjectGroup[type];
            for (int i = 0; i < links.length; i++) {
                valueOwnerObject = valueOwnerObject.GetObject(links[i]);
            }
            return valueOwnerObject;
        }
        }
    }
}
